var BRAND = 'com';
var SITE = 'com'
var localisation = { // Localise the panel content

    DEFAULT_LANGUAGE: 'en',
	
	language_mapping: {
		'zh-hans': 'cn',
		'zh-hant': 'hk'
	},
    
    available_content: {
        images: ['cs', 'de', 'es', 'fr', 'ja', 'nl', 'pl', 'ru', 'tr', 'zh-hant', 'da', 'en', 'fi', 'it', 'ko', 'no', 'pt', 'sv', 'zh-hans'],
        tour: {
            'cs': 30711302001,
            'de': 30692279001,
            'es': 30692278001,
            'fr': 30696603001,
            'ja': 30696601001,
            'nl': 30696600001,
            'pl': 30702945001,
            'ru': 30702943001,
            'tr': 30692268001,
            'zh-hant': 30711293001,
            'da': 30696606001,
            'en': 30711300001,
            'fi': 30702949001,
            'it': 30711297001,
            'ko': 30692275001,
            'no': 30711295001,
            'pt': 30692271001,
            'sv': 30692270001,
            'zh-hans': 30696598001,
			'ro': 52797158001
        },
		player: {DEFAULT_LANGUAGE: 31987695001},
        tour_button: {
            'cs': 'Podívejte se, co nabízíme',
            'de': 'Starte jetzt unsere Tour',
            'es': 'Tour del Sitio',
            'fr': 'Visite Guidée',
            'ja': 'ツアーをみる',
            'nl': 'Neem de Tour',
            'pl': 'Rozpocznij wizytę',
            'ru': 'Совершите экскурсию',
            'tr': 'Turumuza Katılın',
            'zh-hant': '進入本站導覽',
            'da': 'Se en rundvisning',
            'en': 'Take Our Tour', 
            'fi': 'Tee tutustu-miskierros',
            'it': 'Visita Guidata',
            'no': 'Ta vår omvisning',
            'pt': 'Faça Nossa Visita Guiada',
            'sv': 'Ta vår Tour',
            'zh-hans': ' 欢迎参观',
            'hu': 'Tekintse meg bemutatónkat'
        }
    },

	get_language:function(mapping){
		
		var lang = localisation.DEFAULT_LANGUAGE;

        if (typeof miawidget != "undefined" && typeof miawidget.getLanguageCode != "undefined"){        
            
			lang = miawidget.getLanguageCode();
        }

		if (mapping) {

			if(typeof localisation.language_mapping[lang] != 'undefined') {
				
				return localisation.language_mapping[lang];
			}
   		}
        
		return lang;

	},
	
	get_asset: function(asset) {
	    var lang = localisation.get_language();
	    if(!localisation.available_content[asset]) {
	        return null;
	    }
	    
	    return localisation.available_content[asset][lang] || localisation.available_content[asset][localisation.DEFAULT_LANGUAGE];
	},
	
	get_language_by_asset: function(asset) {

	    var lang = localisation.get_language();

	    if(!localisation.available_content[asset]) {
	        return localisation.DEFAULT_LANGUAGE;
	    }
	    else {

	        var index = $.inArray(lang, localisation.available_content[asset]);
	        if(index >= 0) {
	            return lang;
	        }
	        else {

	            return localisation.DEFAULT_LANGUAGE;
	        }
	    }
	},
	
	init_available_content: function() {
		
		for(var i in localisation.available_content) {
						
			if('DEFAULT_LANGUAGE' in localisation.available_content[i]) {

				localisation.available_content[i][localisation.DEFAULT_LANGUAGE] = localisation.available_content[i]['DEFAULT_LANGUAGE'];
				delete localisation.available_content[i]['DEFAULT_LANGUAGE'];				
			}
		}
	},
	
	init:function(){
		
		localisation.init_available_content();

		var lang = localisation.get_language(true) == localisation.DEFAULT_LANGUAGE ? '' : '/' + localisation.get_language(true);

		// Language Specific links
		$('.panel a').each(function(){

				if($(this).attr("href")) {
   					$(this).attr("href",$(this).attr("href").replace('/{LANG}', lang));						
				}


   		});

		var brand_regex = new RegExp('{BRAND}', 'g');
		$('.panel a').each(function(){
			
			if($(this).attr("href")) {
				$(this).attr("href",$(this).attr("href").replace(brand_regex, BRAND));
			}
		});
		
		var brand_regex = new RegExp('{SITE}', 'g');
		$('.panel a').each(function(){
			
			if($(this).attr("href")) {
				$(this).attr("href",$(this).attr("href").replace(brand_regex, SITE));
			}
		});
        
		var start_plate = $('#start-plate');

		if(start_plate.length > 0) {

			var language = localisation.get_language(true);
			var url = $('#start-plate').attr('href');

			if(language == localisation.DEFAULT_LANGUAGE) {
				url = url.replace('{LANG}/', '');
			}
			else {
				url = url.replace("{LANG}", language);	
			}

			$('#start-plate').attr('href', url);
			
		}

	}
	
}